package leetcode.剑指offer.前40;

import org.junit.Test;

/**
 * @author :songyaozhang
 * @date :Created 2021/7/23 19:56
 * @description :https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/
 */
public class 剑指_16_数值的整数次方 {
    @Test
    public void test() {
        Solution solution = new Solution();

    }

    class Solution {
        public double myPow(double x, int n) {
            long N = n;
            N = Math.abs(N);
            double res = 1.0;
            while (N > 0) {
                if (N % 2 == 1) {
                    res *= x;
                }
                x *= x;
                N >>= 1;
            }
            return n > 0 ? res : 1.0 / res;
        }
    }

}
